#include "stdafx.h"

#include "MainMenu.h"
#include "AllLookFeel.h"
#include "LookFeelEditor.h"
#include "LayoutEditor.h"
#include "App.h"

MainMenu::MainMenu()
{
	mLayout = new MGUI_Layout(AllLookFeel::Instance()->GetMenu());

	mBn_Open = new MGUI_Button(AllLookFeel::Instance()->GetButton(), mLayout);
	mBn_Save = new MGUI_Button(AllLookFeel::Instance()->GetButton(), mLayout);

	mBn_Open->SetCaption(L"Open");
	mBn_Save->SetCaption(L"Save");

	mBn_Open->SetRect(MGUI_Rect(true, 0, 0, 50, 24));
	mBn_Save->SetRect(MGUI_Rect(true, 55, 0, 50, 24));

	mBn_Open->SetAlign(MGUI_Align::VCenter);
	mBn_Save->SetAlign(MGUI_Align::VCenter);

	mBn_Open->eventMouseClick += OnOpen(this, &MainMenu::OnOpen_);
	mBn_Save->eventMouseClick += OnSave(this, &MainMenu::OnSave_);

	mLayout_EditMode = new MGUI_Layout(NULL);
	mLayout_EditMode->SetAlign(MGUI_Align::Stretch);
	mLayout_EditMode->SetPickFlag(MGUI_PickFlag::Child);
	mLayout_EditMode->SetOrder(MGUI_Order::TextCursor + 100);

	mCb_EditMode = new MGUI_ComboBox(AllLookFeel::Instance()->GetComboBox(), mLayout_EditMode);
	mCb_EditMode->SetRect(MGUI_Rect(true, 256, 5, 256, 24));

	mCb_EditMode->Append(L"LookFeel");
	mCb_EditMode->Append(L"Layout");
	mCb_EditMode->SetSelectIndex(0);

	mCb_EditMode->eventSelectChanged += OnEditModeChanged(this, &MainMenu::OnEditModeChanged_);
}

MainMenu::~MainMenu()
{
	delete mLayout;
	delete mLayout_EditMode;
}

void MainMenu::Layout()
{
	MGUI_Rect rect;

	rect.x0 = 0;
	rect.y0 = 0;
	rect.x1 = MGUI_Engine::Instance()->GetRect().x1;
	rect.y1 = 32;

	mLayout->SetRect(rect);
}

void MainMenu::OnOpen_()
{
	LayoutEditor::Instance()->Open();
}

void MainMenu::OnSave_()
{
	int index = mCb_EditMode->GetSelectIndex();

	if (index == 0) // LookFeel
	{
		LookFeelEditor::Instance()->Save();
	}
	else if (index == 1) // Layout
	{
		LayoutEditor::Instance()->Save();
	}
}

void MainMenu::OnEditModeChanged_(int _index)
{
	if (_index == 0) // LookFeel
	{
		App::Instance()->SetEditorMode(EM_Lookfeel);
	}
	else // Layout
	{
		App::Instance()->SetEditorMode(EM_Layout);
	}
}

